package com.zw.demo01.controller;

import com.zw.demo01.common.datasource.DruidDataSourceUtil;
import com.zw.demo01.domain.SQLparams;
import com.zw.demo01.service.impl.DynamicDataSourceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: controller
 * @Description TODO
 * @Author: zzw
 * @Date: 2023/3/28 14:03
 * @Version 1.0.0
 */
@Controller
public class  SqlController {

    @Autowired
    DynamicDataSourceServiceImpl dynamicDataSourceService=new DynamicDataSourceServiceImpl();
    @ResponseBody
    @PostMapping("/sql")
    public Map<String,Object> sql(
            @RequestBody
            SQLparams sqLparams

    ){
//        System.out.println(sqLparams);
//        DruidDataSourceUtil.addOrChangeDataSource(dbip,dbport,dbname,dbuser,dbpwd);
        HashMap<String, Object> params = new HashMap<>();
        params.put("dbip",sqLparams.getDbip());
        params.put("dbport",sqLparams.getDbport());
        params.put("dbname",sqLparams.getDbname());
        params.put("dbuser",sqLparams.getDbuser());
        params.put("dbpwd",sqLparams.getDbpwd());
        params.put("type",sqLparams.getType());
        params.put("paramSQL",sqLparams.getParamSQL());
        params.put("param",sqLparams.getParam());
        Map<String, Object> result = dynamicDataSourceService.dynamicExecutive(params);
        System.out.println(result);
        return result;
    }
}
